#ifndef __FORMAT_H__
#define __FORMAT_H__

const DWORD SIG = 'DTFT';
const DWORD HEADER_ALIGN = 0x100;				// header alignment

#pragma pack(1)

class DTFTHeader
{
public:
	DTFTHeader(BYTE Ver)
		: sig(SIG), ver(Ver)
		{}

	virtual DWORD rawSize() const
		{ return sizeof(sig) + sizeof(ver); }

	DWORD size() const 
	{
		DWORD size = rawSize();
		if (size & ~(HEADER_ALIGN - 1))
		{
			size += HEADER_ALIGN;
		}
		size &= ~(HEADER_ALIGN - 1);
		return size;
	}

	void* write(void* pMem)
	{
		assert(pMem);
		BYTE* p = reinterpret_cast<BYTE*>(pMem);

		*reinterpret_cast<DWORD*>(p) = sig;
		p += sizeof(sig);
		*reinterpret_cast<BYTE*>(p) = ver;
		p += sizeof(ver);

		return p;
	}

private:
	DWORD	sig;
	BYTE	ver;
};

class DTFTHeader_v1 :
	public DTFTHeader
{
public:
	DTFTHeader_v1()
		: DTFTHeader(1)
	{}

	void setFontName(const string& Font)
		{ fontName = Font; }

	virtual DWORD rawSize() const
	{
		return DTFTHeader::rawSize() 
			+ sizeof(char) * (fontName.length() + 1)
			+ sizeof(DWORD);
	}

	void* write(void* pMem)
	{
		pMem = DTFTHeader::write(pMem);

		BYTE* p = reinterpret_cast<BYTE*>(pMem);

		memcpy(p, fontName.c_str(), fontName.length() + 1);
		p += sizeof(BYTE) * (fontName.length() + 1);

		*reinterpret_cast<DWORD*>(p) = size();
		p += sizeof(DWORD);

		return p;
	}

private:
	string	fontName;
};

#pragma pack()

#endif // __FORMAT_H__